package qq66179820.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import qq66179820.entities.CommonResult;
import qq66179820.entities.Payment;


/**
 * TODO
 *
 * @author lihj
 * @date 2022/1/23
 */
@Slf4j
@RestController
@RequestMapping("/pay")
public class PaymentController {

    @Value("${server.port}")
    private String SERVER_PORT;

    @GetMapping
    public CommonResult get(long id) {
        Payment payment = new Payment();
        payment.setId(id);
        payment.setSerial("test" + id);
//        int result = paymentService.create(payment);
//        log.info("插入数据的ID:\t" + payment.getId());
        log.info("插入结果：" + payment);
        if (payment != null) {
            return new CommonResult(200, "插入数据成功,serverport:" + SERVER_PORT, payment);
        } else {
            return new CommonResult(444, "插入数据失败", null);
        }
    }

    @GetMapping("/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        Payment payment = new Payment();
        payment.setId(id);
        payment.setSerial("test" + id);

        log.info("***查询结果：" + payment);
        if (payment != null) {
            return new CommonResult(200, "查询数据成功,serverport:" + SERVER_PORT, payment);
        } else {
            return new CommonResult(444, "没有对应记录", null);
        }
    }

    @GetMapping("/{id}")
    public String getId(@PathVariable String id) {

        return "服务端口:" + SERVER_PORT + ", ID:" + id;
    }
}
